﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ArithmeticLibrary;

namespace Derivator
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Zadejte funkci: ");
            string input = Console.ReadLine(); ;

            // dokud neni zadane ukoncovaci slovo end
            while (input != "end")
            {
                try
                {
                    Expression expression = new Expression(input);

                    Function function = new Function(expression);

                    Console.WriteLine("f({1}): {0}", function.Definition.ToString(), function.VariableName);
                    Console.WriteLine("f'({1}): {0}", function.Derivation1.ToString(), function.VariableName);
                    Console.WriteLine("f''({1}): {0}", function.Derivation2.ToString(), function.VariableName);

                    Console.Write("Zadejte hodnotu {0}: ", function.VariableName);

                    input = Console.ReadLine();

                    double d = double.Parse(input);

                    Console.WriteLine("f({1}): {0}", function.Evaluate(d), function.VariableName);
                    Console.WriteLine("f'({1}): {0}", function.Evaluate1stDerivation(d),function.VariableName);
                    Console.WriteLine("f''({1}): {0}", function.Evaluate2ndDerivation(d), function.VariableName);
                    Console.WriteLine();

                    Console.Write("Zadejte funkci: ");
                    input = Console.ReadLine();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    input = Console.ReadLine();
                    continue;
                }
            }
        }
    }
}
